/*
 * twostack.cpp
 * Copyright (C) 2016 libo <libo@tencent.com>
 *
 * Distributed under terms of the MIT license.
 */

#include <stack>
#include <iostream>
#include <stdio.h>

using namespace std;

template <typename T> 
class MyQueue {
public:
  void push(const T& item) {
    _push_stack.push(item);
  }
  void pop() {
    _revert_stack();
    _pop_stack.pop();
  }
  T top() {
    _revert_stack();
    return _pop_stack.top();
  }
  int size() {
    return _push_stack.size() + _pop_stack.size();
  }
private:
  stack<T> _push_stack;
  stack<T> _pop_stack;
  void _revert_stack() {
    if (_pop_stack.size() > 0) return;
    while (!_push_stack.empty()) {
      _pop_stack.push(_push_stack.top());
      _push_stack.pop();
    }
  }
};

int main() {
  MyQueue<int> my_q;
  int x;
  //while (scanf("%d",&x) != EOF) my_q.push(x);
  my_q.push(1);
  my_q.push(2);
  while (my_q.size() > 0) {
    cout << my_q.top() << " ";
    my_q.pop();
  }
  my_q.push(3);
  my_q.push(4);
  my_q.push(5);
  while (my_q.size() > 0) {
    cout << my_q.top() << " ";
    my_q.pop();
  }
};
